package com.cskaoyan.service;

import com.cskaoyan.bean.MarketFootprint;
import com.cskaoyan.bean.MarketUser;
import com.cskaoyan.bean.common.BasePageInfo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.bean.footprint.FootprintVo;
import com.cskaoyan.mapper.MarketFootprintMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author Austin Hsu
 * @Date 2022/9/12 21:49
 */
@Service
public class FootprintServiceImpl implements FootprintService{

    @Autowired
    MarketFootprintMapper marketFootprintMapper;


    @Override
    public CommonData<FootprintVo> query(BasePageInfo info) {
        PageHelper.startPage(info.getPage(),info.getLimit());
        //得到User信息
        MarketUser marketUser = (MarketUser) SecurityUtils.getSubject().getPrincipals().getPrimaryPrincipal();
        Integer uid = marketUser.getId();

        List<FootprintVo> list =marketFootprintMapper.query(uid);
        PageInfo<FootprintVo> pageInfo=new PageInfo<>(list);
        int total = (int) pageInfo.getTotal();
        int pages = pageInfo.getPages();

        CommonData<FootprintVo> data=new CommonData<>(total,pages,info.getPage(),info.getLimit(),list);

        return data;
    }
}
